<div class="row-fluid sortable">
    <div class="box span12">
        <div class="box-header well" data-original-title>
            <h2><i class="icon-edit"></i>Bill</h2>

        </div>
        <script type="text/javascript"  >
            function changecateajax(selectObj) {
                var id = selectObj.value;
                var dataString = id;
                $.ajax({
                    url: "<?php echo base_url() . 'welcome/show_cate_ajax/'; ?>" + dataString,
                    type: 'POST',
                    data: dataString,
                    success: function(output_string) {
                        $(".resultset").html(output_string);
                    }
                });
            }
            
             function changeamountdiscount(selectObj) {
                var id = selectObj.value;
                var dataString = id + '/' + <?php echo $order_id_num?>;
                $.ajax({
                    url: "<?php echo base_url() . 'welcome/changeprice/'; ?>" + dataString,
                    type: 'POST',
                    data: dataString,
                    success: function(output_string) {
                        $(".amountprice").html(output_string);
                    }
                });
            }
            
            function changeamount_ajax(selectObj,order_id) {
                var amount = selectObj.value; 
                var dataString = order_id + '/' + amount;
                $.ajax({
                    url: "<?php echo base_url() . 'welcome/changeamount_ajax/'; ?>" + dataString,
                    type: 'POST',
                    data: dataString,
                    success: function(output_string) {
                        $(".amountvalue").html(output_string);
                    }
                });
            }

            
            function changeitem_ajax(selectObj,order_id) {
                var amount = selectObj.value; 
                var dataString = order_id + '/' + amount;
                $.ajax({
                    url: "<?php echo base_url() . 'welcome/changeitem_ajax/'; ?>" + dataString,
                    type: 'POST',
                    data: dataString,
                    success: function(output_string) {
                        $(".item_status_change").html(output_string);
                    }
                });
            }
            function addRowOrder (tableID) {
          	  var emptyTextBoxes = $('#items_select').filter(function() {
                    return this.value != "";
                });
                if ($('#items_select').val() == 0 ) {
    					return;
                    }
                var item_amount = $('#item_amount').val();
                if ((isNaN(parseInt(item_amount)))||(parseInt(item_amount) < 1) ){
                	item_amount = 1;
                }
                var vSkill = document.getElementById('items_select');
                console.log(vSkill.value);
                var vSkillText = vSkill.options[vSkill.selectedIndex].innerHTML;
                var table = document.getElementById(tableID);
              //  $orderid,$item_id,$amount
                $.ajax({
                    url: "<?php echo base_url() . 'welcome/add_order_item'; ?>"+"/" + <?php echo $order_id_num;?> + "/" + vSkill.value + "/" + item_amount,
                    type: 'POST',
                    success: function(output_string) {
                    }
                });
               
          }
        </script>
        <div class="box-content">
             <div class="control-group">
                <label class="control-label" for="typeahead"> Lập hóa đơn:<font color="red"> <?php echo $user_name;?></font></label>
                
            </div> 
            <?php if($editable == 0):?>
            <div class="control-group">
                <label class="control-label" for="typeahead">Chọn món:</label>
                <div class="controls">
                    <select name="category_select"  
                            onchange="changecateajax(this);">
                        <option value="0" selected="selected">------------</option>
                        <?php foreach ($listcate as $cate): ?>
                            <option value="<?php echo $cate->id; ?>">
                                <?php echo $cate->catename; ?>
                            </option>
                        <?php endforeach; ?> 

                    </select>
                    <div class="resultset">

                    </div>
                    <input type="text" name="item_amount" id="item_amount" />
                    <a href="" class="btn btn-primary" onclick="addRowOrder('dataTable_order')">Thêm món</a>
                    <p class="help-block"></p>
                </div>
            </div>
            <?php endif;?>
            <?php foreach ($order_details as $order): ?>
                <?php echo form_open_multipart('welcome/edit_order/' . $order->id); ?>
                <fieldset> 

                    <div class="control-group">
                        <label class="control-label" for="typeahead">Tên bàn:</label>
                        <div class="controls">
                           <?php if($editable == 0):?>                                       
                        
                           <select name="table_id"  >            
                        	<option value="<?php echo $order->table_id?>" selected="selected"><?php echo $order->order_name; ?></option>
                        	<?php foreach ($listtable as $table): ?>
                            <option value="<?php echo $table->id; ?>">
                                <?php echo $table->table_name; ?>
                            </option>
                       		<?php endforeach; ?> 

                   			</select>
                            <p class="help-block"></p>
                           <?php else:?>
                        	<label class="control-label" for="typeahead"><h3><?php echo $order->order_name; ?></h3></label>
                           <?php endif;?>
                        </div>
                    </div>


                    <div class="control-group">
                        <label class="control-label" for="typeahead"><b>Đã chọn:</b>
                        </label>
                        <div class="controls">
                            <div id="InputsWrapper">
                                <table id="dataTable_order" class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                        <tr> 
                                            <th>Tên món</th>
                                            <th>Số lượng</th> 
                                            <th>Thời gian đặt</th>   
                                            <th>Thực hiện</th>
                                           	<?php if($editable == 0):?>                                       
                                            <th>Hủy</th>
                                            <?php endif;?>
                                        </tr>
                                    </thead>   
                                    <tbody>
                                        <?php foreach ($order_item as $order_item): ?>
                                            <tr>
                                                <td>
                                                    <?php if($editable == 0):?>                                       
                                                
                                                    <select name="item_name_ajax" id="item_name_ajax" onchange="changeitem_ajax(this,<?php echo $order_item->id;?>)">
                                                           <?php foreach($list_item_all as $item_ajax): ?>
                                                            <option value="<?php echo $item_ajax->id?>" <?php if($order_item->item_id == $item_ajax->id):?>selected="selected"<?php endif;?>><?php echo $item_ajax->item;?> </option>
                                                       <?php endforeach;?>
                                                    </select>
                                                     <span class="item_status_change"></span>
                                                     <?php else:?>
                                                    <?php echo $order_item->item_name; ?> 
                                                    <?php endif;?>
                                                </td>
                                                <td>
													<?php if($editable == 0):?>
													<select name="amount_item" id="amount_item" onchange="changeamount_ajax(this,<?php echo $order_item->id;?>)">
                                                            <?php for($i =1;$i <= 50; $i++):?>
                                                           <option value="<?php echo $i ?>" <?php if($i == $order_item->amount):?>selected="selected"<?php endif;?> ><?php echo $i; ?> </option>
                                                               <?php endfor; ?>
                                                    </select>
                                                    <span class="amountvalue"></span>
                                                    <?php else:?>
                                                    <?php echo $order_item->amount;?>
                                                    <?php endif;?>
                                                    </td>
                                                <td><?php echo floor((time() - strtotime($order_item->time_create)) / 60); ?> phút trước</td>
                                                <td><?php if ($order_item->status == '1'): ?>
                                                        <?php echo "Đã mang ra"; ?>
                                                    <?php endif; ?>
                                                    <?php if ($order_item->status == '0'): ?>
                                                        <a  href="<?php echo site_url("welcome/finish_item_order/" . $order_item->id . "/" . $order->id); ?>"> Mang ra </a>
                                                    <?php endif; ?> </td>

                                                
                                                <?php if($editable == 0):?>                   
                                                <td>  
                                                    <a  href="<?php echo site_url("welcome/remove_item_order/" . $order_item->id . "/" . $order->id); ?>"> Xóa </a></td>
                                            	<?php endif;?>
                                            </tr>

                                            <?php endforeach; ?>
                                    </tbody>
                                </table>

                            </div>

                            <p class="help-block"></p>
                        </div>
                    </div>
                    <div class="form-actions"  >
                        DISCOUNT:
                        <select name="discount_value"  onchange="changeamountdiscount(this);"> 
                            <option value="0" selected="selected">0 %</option>
                            <option value="5" >5 %</option>
                            <option value="10" >10 %</option>
                            <option value="15" >15 %</option>
                            <option value="20" >20 %</option>
                            <option value="25" >25 %</option>
                            <option value="30" >30 %</option>
                            <option value="35" >35 %</option>
                            <option value="40" >40 %</option>
                            <option value="45" >45 %</option>
                            <option value="50" >50 %</option> 
                        </select>
                        <br/>
                        <label class="control-label" for="typeahead">Tổng:</label>
                        <div class="controls">
                                Giá chưa discount: <?php echo number_format($total_price); ?> VND<br>
                            <font color='red'> Thành tiền:</font>
                           <h2> <div class='amountprice'> 
                            </div>  </h2>
                             <p class="help-block"></p>
                        </div>
                    </div>

                    <div class="form-actions">

                        <button type="submit" name="bttback" class="btn btn-primary">Quay lại</button>
                         <?php if($editable == 0):?>
                        <?php if($order->status != 1):?>
                        	<button type="submit" name="submit" class="btn btn-primary">Lưu</button>
                        <?php endif;?>
                        <?php endif;?>
                        
                        <?php if($order->status == 0):?>
                            <a class="btn btn-primary" href="<?php echo site_url("welcome/checkout_pending/" . $order->id); ?>">Báo Thanh toán</a>
                        <?php endif;?>
                        <?php if($order->status == 2):?>
                            <a class="btn btn-primary" href="<?php echo site_url("welcome/checkout/" . $order->id); ?>"> Thu tiền</a>
                        <?php endif;?>
                    </div>
                </fieldset>
                <?php echo form_close(); ?>
            <?php endforeach; ?> 

        </div>
    </div><!--/span-->

</div><!--/row-->